﻿<link href="~/Content/default/jiesuan.css" rel="stylesheet" />
 
@{
    ViewBag.Title = "Dc";
    var hid = ViewBag.HID;
    var oid = ViewBag.OID;
    Layout = "~/Views/Shared/_Layout.cshtml";
      
    <script>  
        $(function () {
            GetCategory(@ViewBag.HID);  
            $("#BtnNextOrder").click(function() {    
                var url = "@Url.Action("OrderTemp")?hotelid=" + @ViewBag.HID+"&orderid="+ @ViewBag.OID;
                 window.location = url; 
             });
         });
        function GetCategory(hid) {
            var url = "@Url.Action("GetCategory")?hid=" +hid;
            $.get(url, function(result) { 
                if (result == null)
                    return;
                $.each(result.Data, function (index, row) {
                    var template = $('#CategoryTemp').html(); //获取模版的html
                    var bookData = Mustache.render(template, row);//把每行的数据填充到模版得到html内容
                    $("#CategoryUL").append(bookData);
                });
                $("#CategoryUL dd").each(function () {
                    $(this).click(function () {
                        $("#CategoryUL dd").removeClass("active");
                        $(this).addClass("active");
                        //alert($(this).attr("id")); 
                        $("#CookbookUL").empty();
                        GetCookbook(hid, $(this).attr("id"));
                    });
                });
            }); 
        }
        //显示菜单
        function GetCookbook(hid, cid) {
            var url = "@Url.Action("GetCookbook")?type=Cookbook&hid=" + hid + "&cid=" + cid; 
        $.ajax({
            url: url,
            type: 'Post',
            dataType: 'json',
            success: function (result) {
                if (result.Data.length==0) { 
                    var li = document.createElement('li');
                    var msg = document.createElement('div');
                    $(msg).attr("style", "float:right;width:60%");
                    $(msg).html("本类暂无菜单");
                    $(li).append(msg);
                    document.getElementById('CookbookUL').appendChild(li);
                    return;
                } 
                $.each(result.Data, function (index, row) { 
                    var template = $('#CookbookTemp').html(); //获取模版的html
                    var bookData = Mustache.render(template, row);//把每行的数据填充到模版得到html内容
                    $("#CookbookUL").append(bookData);
                });
                $("#CookbookUL p").each(function () { 
                    $(this).click(function () {   
                        AddOrder($(this).attr('Id'), $(this).attr('Name'), $(this).attr('Price'), 1, @oid);
                       
                    }); 
                });   
            }
        });
        }  
        //添加到菜谱
        function AddOrder(a, b, c,d,e) { 
            //alert(a + "," + b + "," + c + "," + d + "," + e);
            var tempurl = "@Url.Action("OrderTempDetail")";
        $.ajax({
            url: tempurl,
            cache: false,
            type: 'POST',
            dataType: "json", 
            data: {
                CName: b,
                Price: c,
                HCId: a,
                Num: d,
                IsGuest: 0,
                UId:-1,
                orderid:e
            },
            success: function (result) { 
             
                if (result.Data == null)
                    return;  
                $("#orderUL").empty();
                var numCount = 0;
                var priceCount = 0; 
                $.each(result.Data, function (index, row) {
                    priceCount += row.Price*row.Num;
                    numCount += row.Num;
                
                    var template = $('#OrderTemp').html(); //获取模版的html
                    var bookData = Mustache.render(template, row);//把每行的数据填充到模版得到html内容
                    $("#orderUL").append(bookData);
                }); 
                $("#priceCount").html(priceCount);
                $("#numcount").html(numCount); 
            }
        });
    }
    </script>
} 
 <div id="content">  
    <div id="mainContent"> 
        <dl id="CategoryUL" class="dtlcategdtl">
            <dd class="active" id="0">
                <a href="javascript:;">全部</a>
            </dd>
        </dl> 
        <div class="maindishlist">
            <ol id="CookbookUL">
            </ol>
        </div> 
    </div>
    <div id="sideContent">
        <div class="mymenu">
            <h2>我的菜单</h2>
            <div class="menulist">
                <ul id="orderUL">
                </ul> 
                <div class="total-warp">
                    <a href="javascript:void(0);" class="J_DeletCartData"  onclick="DeleteOrderTemp(-1,2)">清空</a>
                    <dl class="price">
                        <dd class="item-count">合计数量：<b id="numcount"></b>份</dd>
                        <dd class="item-tit">合计金额：<b>¥</b> <strong id="priceCount"></strong></dd>
                        <dd class="item-label">节省：<b>¥</b> <strong>20</strong></dd>
                        <dd class="price-other">菜单金额以实际消费为准</dd>
                    </dl>
                    <a class="next-btn" href="#" id="BtnNextOrder">预定</a>
                </div>
            </div>
        </div>
    </div>
</div>
<!--模版-->
<!--菜谱模版-->
<script type="text/template" id="CategoryTemp">   
	  	<dd id="{{Id}}"><a href="javascript:;">{{Name}}</a></dd>  
</script> 
<script type="text/template" id="CookbookTemp">   
	  <li>
					<div class="mainimg"><img src="../../../{{DishImages}}" alt="{{Name}}" width="120" /></div>
					<h3>{{Name}}</h3>
					<dl class="score">
						<dd class="money">￥<strong>{{Price}}</strong></dd>
						<dd class="sales">销量：<b>215</b></dd>
					</dl>
					<p class="setu"  id="{{Id}}" name="{{Name}}" Price="{{Price}}"><a href="javascript:void(0);" >点菜</a></p>
				</li>
</script>
<!--已点菜谱模版-->
 <script type="text/template" id="OrderTemp">  
    <li> 
	    <div class="food-count-del"><a href="javascript:void(0);" data-change="-1" onclick="DeleteOrderTemp({{HCId}},1)">×</a></div>
	    <div class="food-count-name">{{CName}}</div>
	    <div class="food-count-price">{{Price}}</div>
	    <div class="food-count-reduce"  ><a href="javascript:void(0);" data-change="-1" onclick="AddOrder({{HCId}},'{{CName}}',{{Price}},-1);">-</a></div>
	    <div class="food-count-num">{{Num}}</div>
	    <div class="food-count-add"><a href="javascript:void(0);" data-change="1" onclick="AddOrder({{HCId}},'{{CName}}',{{Price}},1);">+</a></div>
    </li>
</script>
